<extend name="Public/base" />
<block name="content">
<script src="__JS__/jjhh.js?v={:C('TKE_VERSION')}"></script>
<div id="content">
    <div id="content-header">
        <div id="breadcrumb">
            <a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i
                class="icon-home"></i> 首页</a> <a href="#" class="current">{$meta_title}</a>
        </div>
    </div>
    <div class="container-fluid"> 
    	<form autocomplete="off">
	    <div class="m-filter clearfix pb20">
	        <div class="filter-pay filter-group form-inline clearfix">
		        <a class="title">选择区域</a><br>
	        	<select data-default="1" required="required" name="province_id" style="width:150px;" class="select-group" id="j-select-province">
					<option value="0">请选择省</option>
				</select>
				<select data-default="1" required="required" name="city_id" style="width:150px;" class="select-group" disabled  id="j-select-city">
					<option value="0">请选择城市</option>
				</select>
				<select data-default="0" required="required" name="ward_id" style="width:150px;" class="select-group" disabled  id="j-select-ward">
					<option value="0">请选择区</option>
				</select>
	        </div>
	    </div>
    
	    <div class="m-filter clearfix pb20">
	        <div class="filter-pay filter-group form-inline clearfix">
		        <a class="title">选择销售网点</a>
		        <span id="sale_box"></span>        
	        </div>
	    </div>
	    
	    <div class="m-filter clearfix pb20 hide" id="activity_content" ></div>
        
        <div class="m-filter clearfix pb20" id="customer_info">
            <div class="filter-turnover filter-group form-horizontal clearfix">
                <a class="title">客户信息</a>
                <div class="control-group">
	              <label class="control-label">姓名 :</label>
	              <div class="controls">
	                <input type="text" class="" id="js_name" maxlength="20" name="customer_name" placeholder="请输入姓名">
	              </div>
	            </div>
                <div class="control-group">
                  <label class="control-label">电话 :</label>
                  <div class="controls">
                    <input type="text" class="pull-left" id="js_phone" name="phone_number" maxlength="11" placeholder="请输入电话（必填）">
                    <button type="button" id="js_search" class="btn btn-primary btn pull-left"><span class="icon-search"></span></button>
                  </div>
                </div>
            </div>
        </div>
        <!-- 报名窗口 -->
        <div id="js_has_sign_common" class="m-filter hide clearfix pb20 pt20" style="text-align:center;color:red">此用户已报名普通票，可以转化VIP！</div>
        <div id="js_sign_board_warp" class="hide">
            <div id="js_sign_board" class="m-filter clearfix pb20">
	            <div class="filter-turnover filter-group form-horizontal clearfix">
	                <a class="title">报名信息</a>
	                <div class="control-group">
	                  <label class="control-label">报名票别 :</label>
	                  <div class="controls">
	                  <label><input type="radio" name="ticket_level" id="js_common" value="0" checked > 普通票 </label>
	                  <label><input type="radio" name="ticket_level" id="js_vip" value="1" > VIP</label>
                    	<input type="hidden" value="0" name="ticket_type" id="ticket_type">
                    	<input type="hidden" value="0" name="activity_join_id" id="activity_join_id">
                    	<input type="hidden" value="0" name="customer_id" id="customer_id">
	                  </div>
	                </div>
	                <div class="control-group" id="js_bus_point">
	                  <label class="control-label">班车点位 :</label>
	                  <div class="controls">
	                    <select class="form-control" style="width: 150px;" id="bus_point_id" name="bus_point_id"></select>
	                  </div>
	                </div>
	                <div class="control-group" id="js_bus_date">
	                  <label class="control-label">班车日期 :</label>
	                  <div class="controls mt5" id="js_bus_date_detail"></div>
	                </div>
	                <br>
	                <div class="control-group fl">
	                    <button type="button" id="js_sign" class="js_submit mr50 btn btn-primary btn pull-right">提交报名</button>
	                </div>
	            </div>
	        </div>
        </div>
        <div id="js_has_sign_vip" class="m-filter hide clearfix pb20 pt20" style="text-align:center;color:red">此用户已报名VIP！</div>
        </form>
    </div>
</div>
<style>
.mr50{
    margin-right: 50px;	
}
.pb20{
	padding-bottom: 20px;
}
.pt20{
	padding-top: 20px;
}
.mt5{
	margin-top: 5px;
}
</style>
<script type="text/javascript">
function getActivity(sale_point_id){
	$('#activity_content').html('').hide();
	$.post("{:U('ServiceSeat/getPointActivity')}", {  sale_point_id : sale_point_id }, call_back, "json");
	return false;
	function call_back(data){
		if(data.status == 1){
			$('#activity_content').html(data.info).hide().fadeIn(300);
		}else{
			tke_alert(data.info, 'alert-error', 2000);
		}
	}
}
$(function (){
     //进行报名
     $('#js_sign').click(function(){
    	 var departure_check$ = $(".departure_check");
    	 if($('#bus_point_id').val() == 0 && departure_check$.find('input:checked').length != 0){
             tke_alert('请选择班车地点', 'alert-error', 2000);
             return false;
    	 }
    	 if($('#bus_point_id').val() != 0 && departure_check$.find('input:checked').length == 0){
             tke_alert('请选择班车时间', 'alert-error', 2000);
             return false;
         }
    	 var bus_num_error = false;
    	 departure_check$.each(function(){
    		 if(($(this).find('input:checked').length == 0 && $(this).find("input[type='text']").val() != '') || ($(this).find('input:checked').length != 0 && $(this).find("input[type='text']").val() == '')){
    			 bus_num_error = true;
    		 }
    	 });
    	 if(bus_num_error){
    		 tke_alert('人数和乘车日期必须对应', 'alert-error', 2000);
             return false;
    	 }
    	 $.post("{:U('ServiceSeat/salePointSignUp')}", $('form').serialize(), call_back, "json");
    	 return false;
    	 function call_back(data){
    		 if(data.status == 1){
    			 tke_alert(data.info, 'alert-success', 2000);
    			 $('#js_name,#js_phone').val('');
    			 $('#js_sign_board_warp').hide();
                 $("#js_has_sign_common").hide();
    		 }else{
 				tke_alert(data.info, 'alert-error', 2000);
    		 }
    	 }
     });
     //报名查询
     $('body').on('click','.js_activity',function(){
    	 if($('#js_phone').val() != ''){
/*     		 if(/^(13[\d]{9}|15[\d]{9}|17[\d]{9}|18[\d]{9})$/.test($('#js_phone').val()) == false){
                 tke_alert('电话输入错误', 'alert-error', 2000);
                 return false;
             } */
             var that$ = $(this);
             $(this).attr('disabled',true);
             //重置HTML
             $('#bus_point_id').html('');
             $('#js_bus_date_detail').html('');
             //重置参数
             $('#ticket_type,#activity_join_id,#customer_id').val('');
             //数据获取
             $.post("{:U('ServiceSeat/getActivitySign')}",{
                 'activity_id' : $('.js_activity:checked').val(),
                 'phone' : $('#js_phone').val(),
                 'customer_name' : $('#js_name').val()
             },function(json){
                 if(json.status == 1){
                     //console.log(json);
                     //可报名
                     if(json.join.status == 2){
                          $('#bus_point_id').html(json.bus);
                          $('#js_bus_date_detail').html(json.departure);
                          $('#js_has_sign_vip').hide();
                          $('#js_sign_board_warp').show();
                          set_value("#js_common", '0');
                          $("#js_common").click();
                          $("#js_has_sign_common").hide();
                          $("#js_common").attr('disabled',false);
                          set_value("bus_point_id", 0);
                     }else if(json.join.status == 1){
                         //已报名普通票
                         if(json.join.data.ticket_level == "0"){
                             $('#bus_point_id').html(json.bus);
                             $('#js_bus_date_detail').html(json.departure);
                             $('#js_has_sign_vip').hide();
                             $('#js_sign_board_warp').show();
                             if(json.bus_id > 0){
                                 set_value("bus_point_id", json.bus_id);
                             }else{
                                 set_value("bus_point_id", 0);
                             }
                             //转化参数
                             set_value("#js_vip", '1')
                             $("#js_vip").click();
                             $("#js_common").attr('disabled',true);
                             $("#js_has_sign_common").show();
                             $('#ticket_type').val(1);
                             $('#activity_join_id').val(json.join.data.activity_join_id);
                             $('#customer_id').val(json.join.data.customer_id);
                         }else{
                             //已报名VIP
                             $("#js_common").attr('disabled',false);
                             $("#js_has_sign_common").hide();
                             $('#js_sign_board_warp').hide();
                             $('#js_has_sign_vip').show();
                         }
                     }else{
                         tke_alert(json.join.info, 'alert-error', 2000);
                     }
                 }else{
                     tke_alert('查找失败', 'alert-error', 2000);
                 }
                 that$.attr('disabled',false);
             },'json');
    	 }
     });
     $('#js_search').click(function(){
    	if($('.js_sale_point:checked').length == 0){
            tke_alert('请选择销售网点', 'alert-error', 2000);
            return false;
         }
    	if($('.js_activity:checked').length == 0){
 			tke_alert('请选择活动', 'alert-error', 2000);
     		return false;
     	}
/*      	if(/^(13[\d]{9}|15[\d]{9}|17[\d]{9}|18[\d]{9})$/.test($('#js_phone').val()) == false){
 			tke_alert('电话输入错误', 'alert-error', 2000);
     		return false;
     	} */
     	var that$ = $(this);
     	$(this).attr('disabled',true);
     	//重置HTML
     	$('#bus_point_id').html('');
     	$('#js_bus_date_detail').html('');
        //重置参数
        $('#ticket_type,#activity_join_id,#customer_id').val('');
        //数据获取
     	$.post("{:U('ServiceSeat/getActivitySign')}",{
     		'activity_id' : $('.js_activity:checked').val(),
     		'phone' : $('#js_phone').val(),
     		'customer_name' : $('#js_name').val()
     	},function(json){
     		if(json.status == 1){
     			//console.log(json);
     			//可报名
     			if(json.join.status == 2){
                     $('#bus_point_id').html(json.bus);
      				 $('#js_bus_date_detail').html(json.departure);
                     $('#js_has_sign_vip').hide();
                     $('#js_sign_board_warp').show();
                     set_value("#js_common", '0');
                     $("#js_common").click();
                     $("#js_has_sign_common").hide();
                     $("#js_common").attr('disabled',false);
     			}else if(json.join.status == 1){
     				//已报名普通票
     				if(json.join.data.ticket_level == "0"){
                        $('#bus_point_id').html(json.bus);
          				$('#js_bus_date_detail').html(json.departure);
                        $('#js_has_sign_vip').hide();
                        $('#js_sign_board_warp').show();
                        if(json.bus_id > 0){
                        	set_value("bus_point_id", json.bus_id);
                        }else{
                        	set_value("bus_point_id", 0);
                        }
                        //转化参数
                        set_value("#js_vip", '1')
                        $("#js_vip").click();
                        $("#js_common").attr('disabled',true);
                        $("#js_has_sign_common").show();
                        $('#ticket_type').val(1);
                        $('#activity_join_id').val(json.join.data.activity_join_id);
                        $('#customer_id').val(json.join.data.customer_id);
     				}else{
     					//已报名VIP
                        $("#js_common").attr('disabled',false);
                        $("#js_has_sign_common").hide();
                        $('#js_sign_board_warp').hide();
     				    $('#js_has_sign_vip').show();
     				}
     			}else{
         			tke_alert(json.join.info, 'alert-error', 2000);
     			}
     		}else{
     			tke_alert('查找失败', 'alert-error', 2000);
     		}
            that$.attr('disabled',false);
     	},'json');
     });
     
    //选择区以后获取网点
	$('#j-select-ward').click(function(){
		var data = {
			province_id : $('#j-select-province').val(),
			city_id : $('#j-select-city').val(),
			ward_id : $(this).val()
		}
		$.post("{:U('ServiceSeat/getPointList')}", data , call_back, "json");
		return false;
		function call_back(data){
			if(data.status == 1){
				$('#sale_box').html(data.info);
			}else{
    			tke_alert(data.info, 'alert-error', 2000);
    			$('#sale_box').html(data.info);
			}
		}
		
	});    
    //省市区联动
    var url_area = {
    		"province" :"{:U('ServiceApi/getProvinceList')}",
            "city" :"{:U('ServiceApi/getProvinceCityList')}",
            "ward": "{:U('ServiceApi/getCityWard')}",
            "village": "{:U('ServiceApi/getWardVillage')}"
        }
    // 初始化select
    jjhh_select_area(url_area, 3);
});
//导航高亮
highlight_subnav("{:U('ServiceSeat/salePointSignUp')}");
</script>
</block>